package com.magina.common.init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 文件名称：MaginaApiApplicationInitRunner</br>
 * 初始作者： Magina.Hu</br>
 * 创建日期： 2019/4/23</br>
 * 功能说明： 初始化运行类 <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者 日期 修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2019-2020 .All rights reserved.<br/>
 */
@Component
public class MaginaApiApplicationInitRunner implements ApplicationRunner {

    /**
     * redis工具类
     */
    @Autowired
    private RedisTemplate redisTemplate;;

   private static final String INIT_PARAMS = "initParams";

    @Override
    public void run(ApplicationArguments args) throws Exception {

        if (redisTemplate.hasKey(INIT_PARAMS)) {
            redisTemplate.delete(INIT_PARAMS);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        //实际上  缓存字典数据
        for (int i = 0; i < 4; i++) {
            map.put("asd"+i,"qwewqeqw" + i);
        }
        redisTemplate.opsForValue().set(INIT_PARAMS,map);
    }

}
